<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="modelss" :rules="validatorRules">
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serverId" label="加钟项目">
          <a-select v-model="modelss.serverId" placeholder="请选择项目" @focus="focus">
            <a-select-option :value="item.id" v-for="(item, index) in SelectionDate" :key="index"
              >{{ item.title }} - {{ item.price }}元</a-select-option
            >
          </a-select>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="num" label="加钟数量">
          <!-- <a-input placeholder="请输入金额" v-model="modelss.num" /> -->
          <a-input-number placeholder="请输入加钟数量" v-model="modelss.num" :min="1" style="width: 250px" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, MethodDataAdd, MethodDataAddss } from '@/api/manage'
import moment from 'moment'

export default {
  name: 'XhdjUserInfoModal',
  data () {
    return {
      title: '操作',
      visible: false,
      model: {},
      modelss: {
        orderId: '',
        serverId: '',
        num: ''
      },
      SelectionDate: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {
        serverId: [{ required: true, message: '请选择加钟项目!' }],
        num: [{ required: true, message: '请输入数量!' }]
      },
      url: {
        add: '/order/xhdjAppCoachOrder/coachSpeed',
        edit: '/order/xhdjAppCoachOrder/coachSpeed'
      }
    }
  },
  created () {},
  methods: {
    focus () {
      console.log('jnfksdj')
      MethodDataAdd({ id: this.model.id }).then(res => {
        console.log(res)
        if (res.code == 200) {
          this.SelectionDate = res.result
        }
      })
    },
    add () {
      //初始化默认值
      this.edit({})
    },
    edit (record) {
      this.model = Object.assign({}, record)
      this.modelss.orderId = this.model.id
      this.visible = true
    },
    close () {
      this.$emit('close')
      this.model = {}
      this.modelss = {}
      this.SelectionDate = []
      this.visible = false
      this.$refs.form.clearValidate()
    },
    handleOk () {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          console.log('触发表单验证')
          MethodDataAddss(this.modelss)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        } else {
          return false
        }
      })
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style lang="less" scoped></style>
